<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Reply extends MY_Controller {

	public function __construct(){
		parent::__construct();
		$this->load->model('topic_model','topic');
		$this->load->model('reply_model','reply');
	}

	function ajaxlist(){

		if(empty($this->p['id'])) die;
		$id = intval($this->p['id']);
		$pagenum = intval($this->p['pagenum']);
		$pagenum = ($pagenum<=0) ? 1 : $pagenum; 
		
		//取得主题回复
		$list_reply = $this->reply->get_by_page($id,$pagenum);
		$this->_data['list_reply'] = $list_reply;
		
		echo $this->load->view('reply/ajax_list.php',$this->_data,true);
		
	}
	
	function del(){
		$this->check_ajax_login();
		if(empty($this->p['id'])) die;
				
		//只能删自己的
		$reply = $this->cm->get_by_id($this->tbl_reply,$this->p['id']);
		if($reply->poster_id != $this->loginer->id) die;
		
		$this->cm->update($this->tbl_reply,array('is_del'=>1),array('id'=>$this->p['id']));
	}
}

